import Vue from "vue";
import router from "vue-router";
import AwakeBB from "@/views/bb/AwakeBB.vue"
import AwakeBBCreate from "@/views/bb/AwakeBBCreate.vue"
import GachaBB from '@/views/bb/GachaBB.vue'
import EquipmentBB from '@/views/bb/EquipmentBB.vue'
import AwakeSinoAlice from '@/views/sinoalice/AwakeSinoAlice.vue'
import Error from '@/views/common/Error.vue'
Vue.use(router);

let routes = [
	{
		path: '/',
		name: '主页', // 路由名称
		component: AwakeBB // 组件对象
	},
	{
		path: '/awakeBBCreate',
		name: '觉醒开发', 
		component: AwakeBBCreate 
	},
	{
		path: '/error',
		name: '404', 
		component: Error 
	},
	{
		path: '/gachaBB',
		name: '祈愿',
		component: GachaBB
	},
	{
		path: '/equipmentBB',
		name: '装备', 
		component: EquipmentBB 
	},
	
	{
		path: '/awakeBB',
		name: '崩坏学园2', 
		component: AwakeBB 
	},
	// {
	// 	path: '/awakeSinoAlice',
	// 	name: 'SinoAlice', 
	// 	component: AwakeBB 
	// },

];

let spineRoutersList = routes.slice(5, routes.length);

export {spineRoutersList};

const drouter = new router({
	mode: 'hash',
	routes
});

// 路由拦截器
drouter.beforeEach(async (to, from, next) => {
	if (to.path === '/' || to.path === '/error') {
		// 不加会死循环
		next();
	} else {
		let flag = true;
		routes.forEach(function(value,index,array){
			if (to.path === value.path){
				flag = false;
			}
		});
		if (flag){
			next({
				path: '/error'
			})
		}else {
			next();
		}
	}
});

export default drouter;